package staff

import (
	"context"
	"fmt"
	"strconv"

	model "service/model/hr"
	mCache "service/model/hr_cache"
	"service/model/mod"

	gpb "gitee.com/cloudapex/protos/hr/pb"
	gpa "gitee.com/cloudapex/protos/hr_cache/pb"

	"gitee.com/cloudapex/ulern/htp"
	"gitee.com/cloudapex/ulern/util"
	"github.com/gin-gonic/gin"
)

/*
 * 描述: 添加新员工入职
 * 路由: staff/addStaff
 * 方法: POST
 *********************************************************************/

type StaffAdd struct {
	Phone      string  `form:"phone" json:"phone" binding:"required"`       //手机号
	NumberId   string  `form:"cardId" json:"cardId" binding:"required"`     //身份证号
	NumberName string  `form:"cardName" json:"cardName" binding:"required"` //身份证姓名
	TWorkId    int64   `form:"tWorkId" json:"tWorkId"`                      //招聘人
	WId        int64   `form:"wId" json:"wId" binding:"required"`           //岗位ID
	RuleId     int64   `form:"ruleId" json:"ruleId"`                        //角色ID
	ShowId     []int64 `form:"showId" json:"showId"`                        //组织架构ID
	CreateAt   int64   `form:"creatAt" json:"creatAt" binding:"required"`   //入职时间
}

func (this *StaffAdd) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	fmt.Println("测试流程")
	rsp, err := model.StaffServer.HrAddUser(ctx, &gpb.HrBaseReq{
		CId:        jwtUser.CId,
		NumberId:   this.NumberId,
		NumberName: this.NumberName,
		Phone:      this.Phone,
		TWorkId:    this.TWorkId,
		WId:        this.WId,
		RoleId:     this.RuleId,
		ShowIds:    this.ShowId,
		CreatAt:    this.CreateAt,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	// 离职了没有解禁 录入不成功
	if rsp.Status >= 2 && rsp.Status != 4 {
		return htp.RespErr(htp.CodeSysError, rsp.Message, err)
	}
	if rsp.Status < 2 {
		//插入合同信息
		contReq := make([]*gpb.BaseUInfo, 0)

		contPara := new(gpb.BaseUInfo)
		contPara.Hid = rsp.Id
		contReq = append(contReq, contPara)

		model.StaffServer.EditContract(ctx, &gpb.StaffContractReq{
			OperId:     jwtUser.UId,
			BaseUInfos: contReq,
			State:      1,
			ContType:   0,
			ContAt:     0,
		})

		//插入社保信息
		socReq := make([]*gpb.BaseUInfo, 0)
		//批量修改多个员工的合同
		socPara := new(gpb.BaseUInfo)
		socPara.Hid = rsp.Id
		socReq = append(socReq, socPara)
		model.StaffServer.EditInsurance(ctx, &gpb.StaffInsuranceReq{
			BaseUInfos: socReq,
			State:      1,
			City:       "",
			At:         0,
			OperId:     jwtUser.UId,
		})
	}
	//添加一条岗位变更记录
	_, err = model.Framework.AddChangeFramRole(ctx, &gpb.ChangeFraRoleReq{
		CId:      jwtUser.CId,
		UId:      rsp.Id,
		OperId:   jwtUser.UId,
		FrameIds: this.ShowId,
		RoleId:   this.RuleId,
		WId:      this.WId,
	})

	// 添加进缓存
	mCache.StaffCacheServer.AddStaffCacheInfo(ctx, &gpa.HrBaseCacheReq{
		Id:         rsp.Id,
		CId:        jwtUser.CId,
		NumberId:   this.NumberId,
		NumberName: this.NumberName,
		Phone:      this.Phone,
		TWorkId:    this.TWorkId,
		WId:        this.WId,
		WorkId:     rsp.WorkId,
		RoleId:     this.RuleId,
		CreatAt:    this.CreateAt,
	})

	return htp.RespOK("", rsp.Message)
}

/*
 * 描述: 查询当前员工信息
 * 路由: staff/getStaff
 * 方法: GET
 *********************************************************************/
type StaffGet struct {
	UserId int64 `form:"userId" json:"userId" binding:"required"` //员工ID
}

func (this *StaffGet) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	rsp, err := model.StaffServer.HrGetUser(ctx, &gpb.HrBaseReq{
		Id:  this.UserId,
		CId: jwtUser.CId,
	}) // rs = null
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 查询员工列表
 * 路由: staff/getStaffList
 * 方法: GET
 *********************************************************************/
type StaffList struct {
	Phone      string `form:"phone" json:"phone"`           //手机号
	City       string `form:"city" json:"city"`             //工作城市
	WorkId     int64  `form:"workId" json:"workId"`         //员工ID
	NumberId   string `form:"numberId" json:"numberId"`     //身份证号
	WorkName   string `form:"tWorkName" json:"tWorkName"`   //招聘人
	Name       string `form:"userName" json:"userName"`     //姓名
	WId        int64  `form:"wId" json:"wId"`               //岗位ID
	RoleId     int64  `form:"roleId" json:"roleId"`         //角色ID
	ShowId     int64  `form:"showId" json:"showId"`         //组织架构ID
	State      int64  `form:"inState" json:"inState"`       //在职状态
	RegState   int64  `form:"resState" json:"resState"`     //登记状态
	InAt       int64  `form:"inAt" json:"inAt"`             //入职时间
	FirstState int64  `form:"firstState" json:"firstState"` //是否首次入职
	PinUid     int64  `form:"pinUserId" json:"pinUserId"`   //招聘人ID.
	Tag        int64  `form:"tagId" json:"tagId"`           //离职标签
	PoFraId    int64  `form:"poFraId" json:"poFraId"`       //员工岗位组织架构（搜索条件）
	TimeReq    []struct {
		Tag   int64 `form:"tag" json:"tag"`         //1入职时间 2社保缴费时间 3合同时间 4 离职时间 5转正时间
		Start int64 `form:"startAt" json:"startAt"` //开始时间
		End   int64 `form:"endAt" json:"endAt"`     //结束时间
	} `form:"timeRep" json:"timeRep"`
	Page  int64 `form:"page" json:"page"`   //页码
	Count int64 `form:"count" json:"count"` //总数
}
type StaffECode int // 错误码
const (
	Staff_ParameterError StaffECode = iota + 1
	StaffCode_ParameterError
)

func (this *StaffList) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	if jwtUser.CId < 0 {
		return htp.RespErr(int(StaffCode_ParameterError), "参数错误", nil)
	}
	fmt.Println("对象", this.TimeReq)
	timeReq := make([]*gpb.TimeReq, 0)
	if len(this.TimeReq) > 0 {
		for _, v := range this.TimeReq {
			timePara := new(gpb.TimeReq)
			timePara.Tag = v.Tag
			timePara.Start = v.Start
			timePara.End = v.End
			timeReq = append(timeReq, timePara)
		}
	}
	fmt.Println("组合", timeReq)

	rsp, err := model.StaffServer.GetDetailList(ctx, &gpb.HrDetailReq{
		Count: this.Count,
		Page:  this.Page,
		BaseReq: &gpb.HrBaseReq{
			CId:        jwtUser.CId,
			Phone:      this.Phone,
			WorkId:     this.WorkId,
			TWorkName:  this.WorkName,
			NumberId:   this.NumberId,
			NumberName: this.Name,
			City:       this.City,
			WId:        this.WId,
			RoleId:     this.RoleId,
			ShowId:     this.ShowId,
			State:      this.RegState,
			PoFraId:    this.PoFraId,
		},
		InOutReq: &gpb.InOutReq{
			State:    this.State,
			InAt:     this.InAt,
			Turnover: this.FirstState,
			PinUid:   this.PinUid,
			TimeReq:  timeReq,
			Tag:      this.Tag,
		},
	})
	//去离职标签
	e, err := model.StaffServer.GetQuitTag(ctx, &gpb.QuitTagReq{
		CId: jwtUser.CId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	//获取所有组织架构该企业下
	var vName string

	var userIds []int64

	if rsp != nil && len(rsp.ModelDetails) > 0 {
		//查询缓存里的组织架构信息
		wRes, err := mCache.FrameWorkCache.FrameCacheReqList(ctx, &gpa.FrameworkCacheReq{
			CId: jwtUser.CId,
		})
		if err != nil {
			return htp.RespModelErr("", err)
		}

		for _, v := range rsp.ModelDetails {
			userIds = append(userIds, v.BaseRes.Id)
		}
		fmt.Println(userIds)
		//查询 每个人的 多组织架构
		res, err := model.StaffServer.GetStaffShows(ctx, &gpb.StaffShowsReq{
			Hids: userIds,
		})
		if err != nil {
			return htp.RespModelErr("", err)
		}

		for _, v := range rsp.ModelDetails {
			vName = ""
			for _, ve := range e.QuitTags {
				if v.StaffInOut.Tag == ve.Id {
					v.StaffInOut.TagName = ve.Name
				}
			}
			fmt.Println(res.StaffShows)
			for _, v1 := range res.StaffShows {
				if v.BaseRes.Id == v1.HId {
					fmt.Println(v1.ShowId)
					util.Debug("查询个人的组织架构%d", v1.ShowId)
					_, has := wRes.FrameMap[v1.ShowId]
					if has {
						//vName += mCache.FrameWorkCache.GetFrameName(v1.ShowId, jwtUser.CId, wRes) + "，"

					}
					rsp, err := mCache.FrameWorkCache.GetFraNameByShowIdList(ctx, &gpa.FullReqUIdsReq{CId: jwtUser.CId, Ids: []uint64{uint64(v1.ShowUIntId)}})
					if err == nil {
						vName += rsp.FullUList[0].FullName + ","
					}
				}
			}
			util.Debug("查询个人的组织架构名称%s", vName)
			v.BaseRes.FName = vName
		}

	}

	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 获取岗位列表
 * 路由: staff/getPostList
 * 方法: GET
 *********************************************************************/
type PostList struct {
	FrameId int64 `form:"frameId" json:"frameId"` //岗位ID
}

func (this *PostList) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	if jwtUser.CId < 0 {
		return htp.RespErr(int(StaffCode_ParameterError), "参数错误", nil)
	}

	rsp, err := model.Posts.GetPostList(ctx, &gpb.PostBaseReq{
		CId:     jwtUser.CId,
		FrameId: this.FrameId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 获取岗位列表
 * 路由: staff/delPost
 * 方法: POST
 *********************************************************************/
type PostDel struct {
	Id int64 `form:"postId" json:"postId" binding:"required"` //岗位ID
}

func (this *PostDel) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.Posts.DelPost(ctx, &gpb.PostBaseReq{
		Id: this.Id,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 添加岗位
 * 路由: staff/addPost
 * 方法: GET
 *********************************************************************/
type PostAdd struct {
	Name    string `form:"postName" json:"postName" binding:"required"` //    岗位名称
	FrameId int64  `form:"frameId" json:"frameId" binding:"required"`   //    组织架构id
	CId     int64  `form:"cId" json:"cId" binding:"required"`           //    公司ID
}

func (this *PostAdd) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	if jwtUser.CId < 0 {
		return htp.RespErr(int(StaffCode_ParameterError), "参数错误", nil)
	}

	rsp, err := model.Posts.AddPost(ctx, &gpb.PostBaseReq{
		CId:     this.CId,
		Name:    this.Name,
		FrameId: this.FrameId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", &struct {
		PostId int64 `json:"postId"`
	}{rsp.Id})
}

/*
 * 描述: 获取单个岗位列表
 * 路由: staff/delPost
 * 方法: POST
 *********************************************************************/
type PostGet PostDel

func (this *PostGet) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	if jwtUser.CId < 0 {
		return htp.RespErr(int(StaffCode_ParameterError), "参数错误", nil)
	}

	rsp, err := model.Posts.GetPost(ctx, &gpb.PostBaseReq{
		CId: jwtUser.CId,
		Id:  this.Id,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 设置员工离职
 * 路由: staff/setStaffOut
 * 方法: POST
 *********************************************************************/
type SetStaffOut struct {
	LzAt   int64  `form:"lzAt" json:"lzAt"`     //    离职时间
	QId    int64  `form:"qId" json:"qId"`       //    离职标签
	Id     int64  `form:"id" json:"id"`         //    离职人员
	LzMark string `form:"lzMark" json:"lzMark"` //    离职备注
}

func (this *SetStaffOut) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)
	rsp, err := model.StaffServer.SetQuit(ctx, &gpb.InOutReq{
		LzAt:   this.LzAt,
		QId:    this.QId,
		LZMark: this.LzMark,
		Id:     this.Id,
		OperId: jwtUser.UId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 解禁离职状态
 * 路由: staff/setStaffOn
 * 方法: POST
 *********************************************************************/
type SetStaffOn SetStaffOut

func (this *SetStaffOn) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.StaffServer.OnQuit(ctx, &gpb.InOutReq{
		Id: this.Id,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

type SetStaffIn struct {
	ZzAt int64 `form:"zzAt" json:"zzAt" binding:"required"` //    转正时间
	Id   int64 `form:"id" json:"id" binding:"required"`     //    转正ID
}

func (this *SetStaffIn) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	rsp, err := model.StaffServer.SetZz(ctx, &gpb.InOutReq{
		ZZAt:   this.ZzAt,
		Id:     this.Id,
		OperId: jwtUser.UId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

type StaffTag struct {
}

func (this *StaffTag) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)
	rsp, err := model.StaffServer.GetQuitTag(ctx, &gpb.QuitTagReq{
		CId: jwtUser.CId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 获取员工银行信息
 * 路由: staff/getBankInfo
 * 方法: GET
 *********************************************************************/
type StaffBankInfo StaffGet

func (this *StaffBankInfo) Handle(c *gin.Context, ctx context.Context) htp.Response {

	rsp, err := model.StaffServer.GetBanks(ctx, &gpb.StaffBank{
		Hid: this.UserId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 获取员工教育信息
 * 路由: staff/getBankInfo
 * 方法: GET
 *********************************************************************/
type StaffEduInfo StaffGet

func (this *StaffEduInfo) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.StaffServer.GetEduList(ctx, &gpb.StaffEdu{
		Hid: this.UserId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 修改员工基本信息
 * 路由: staff/setStaffInfo
 * 方法: POST
 *********************************************************************/
type StaffInfo struct {
	UserId      int64  `form:"userId" json:"userId" binding:"required"`                   //员工ID
	CId         int64  `form:"cId" json:"cId"`                                            //公司ID
	NumberId    string `form:"cardId" json:"cardId" binding:"required,max=18"`            //身份证号
	NumberName  string `form:"cardName" json:"cardName" binding:"required"`               //身份证姓名
	Sex         int32  `form:"sex" json:"sex" binding:"required"`                         //性别: 1 默认，2 男，3 女
	Name        string `form:"userName" json:"userName" binding:"required"`               //姓名
	Birthday    int64  `form:"birthDay" json:"birthDay" binding:"required"`               //出生日期
	Phone       int64  `form:"phone" json:"phone" binding:"required"`                     //手机号
	HujiType    int32  `form:"hujiType" json:"hujiType" binding:"required"`               //户籍类型：1 默认，2 农业户籍，3 非农业户籍
	HujiAddress string `form:"hujiAddress" json:"hujiAddress" binding:"required,max=200"` //户籍地址
	NowAddress  string `form:"nowAddress" json:"nowAddress" binding:"required,max=200"`   //当前住址
	Emall       string `form:"email" json:"email"`                                        //电子邮件
	Marriage    int32  `form:"marriAge" json:"marriAge" binding:"required"`               //婚姻状态：1默认， 1 未婚，2 已婚
	NumberUrl   string `form:"cardUrl" json:"cardUrl" binding:"required"`                 //身份证照片（ http://yuxue.net/number_before.jpg,http://yuxue.net/number_after.jpg ）前/后
	UrgentName  string `form:"urgentName" json:"urgentName" binding:"required"`           //紧急联系人姓名
	UrgentPhone string `form:"urgentPhone" json:"urgentPhone" binding:"required"`         //紧急联系人手机号
	EduImage    string `form:"eduImage" json:"eduImage" `                                 //毕业证照片
	City        string `form:"city" json:"city"`                                          //工作城市
	TWorkId     int64  `form:"tWorkId" json:"tWorkId"`                                    //招聘人工号
	TuijianUid  int64  `form:"tuijianUid" json:"tuijianUid"`                              //推荐人工号
	UpNote      string `form:"upNote" json:"upNote"`                                      //编辑备注
}

func (this *StaffInfo) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.StaffServer.UpdateUser(ctx, &gpb.HrBaseReq{
		Id:          this.UserId,
		CId:         1,
		NumberId:    this.NumberId,
		NumberName:  this.NumberName,
		Sex:         this.Sex,
		Name:        this.Name,
		Birthday:    this.Birthday,
		Phone:       strconv.FormatInt(this.Phone, 10),
		HujiType:    this.HujiType,
		HujiAddress: this.HujiAddress,
		NowAddress:  this.NowAddress,
		Emall:       this.Emall,
		Marriage:    this.Marriage,
		NumberUrl:   this.NumberUrl,
		UrgentName:  this.UrgentName,
		UrgentPhone: this.UrgentPhone,
		EducImg:     this.EduImage,
		City:        this.City,
		TWorkId:     this.TWorkId,
		TuijianUid:  this.TuijianUid,
		UpNote:      this.UpNote,
	})
	fmt.Println(err)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	if rsp.Status != 0 {
		return htp.RespErr(int(rsp.Status), "更新员工基本信息失败", nil)
	}
	return htp.RespOK("", nil)
}

/*
 * 描述: 修改员工银行卡信息
 * 路由: staff/setStaffBankInfo
 * 方法: POST
 *********************************************************************/
type UpdateBankInfo struct {
	BankInfo []struct {
		Id         int64  `form:"bankId" json:"bankId"`         //银行卡ID
		CardNumber string `form:"cardNumber" json:"cardNumber"` //银行卡号
		BankInfo   string `form:"bankInfo" json:"bankInfo"`     //支行信息
		BankType   int64  `form:"bankType" json:"bankType"`     //银行卡类型
		BankUrl    string `form:"bankUrl" json:"bankUrl"`       //银行卡照片
	} `json:"bankInfos"`
}

func (this *UpdateBankInfo) Handle(c *gin.Context, ctx context.Context) htp.Response {
	if len(this.BankInfo) > 0 {
		var banks []*gpb.StaffBank
		for _, v := range this.BankInfo {
			bank := new(gpb.StaffBank)
			bank.Id = v.Id
			bank.CardNumber = v.CardNumber
			bank.BankUrl = v.BankUrl
			bank.BankType = v.BankType
			bank.BankInfo = v.BankInfo
			banks = append(banks, bank)
		}
		var req = new(gpb.StaffBankReq)
		req.StaffBanks = banks
		rsp, err := model.StaffServer.UpdateBank(ctx, req)
		fmt.Println(err)
		if err != nil {
			return htp.RespModelErr("", err)
		}
		if rsp.Status != 0 {
			return htp.RespModelErr("更新员工基本信息失败", nil)
		}
	}

	return htp.RespOK("", nil)
}

/*
 * 描述: 修改员工教育经历
 * 路由: staff/setStaffEduInfo
 * 方法: POST
 *********************************************************************/
type UpdateEduInfo struct {
	EduCation []struct {
		Id         int64  `form:"id" json:"id"`                 //学历ID
		EduCation  int64  `form:"eduCation" json:"eduCation"`   //学历
		SchoolName string `form:"schoolName" json:"schoolName"` //学校
		InAt       int64  `form:"inAt" json:"inAt"`             //入学时间
		OutAt      int64  `form:"outAt" json:"outAt"`           //毕业时间
		MaJor      string `form:"maJor" json:"maJor"`           //专业
	} `json:"eduCation"`
}

func (this *UpdateEduInfo) Handle(c *gin.Context, ctx context.Context) htp.Response {
	fmt.Println(this)
	//修改教育经历
	if len(this.EduCation) > 0 {
		for _, v := range this.EduCation {
			_, err := model.StaffServer.UpdateEdu(ctx, &gpb.StaffEdu{
				Id:         v.Id,
				Education:  v.EduCation,
				SchoolName: v.SchoolName,
				InAt:       v.InAt,
				OutAt:      v.OutAt,
				Major:      v.MaJor,
			})
			if err != nil {
				return htp.RespModelErr("更新员工基本信息失败", err)
			}
		}
	}
	return htp.RespOK("", nil)
}

/*
 * 描述: 员工的离职原因
 * 路由: staff/staffOutDetail
 * 方法: GET
 *********************************************************************/
type StaffOutDetail StaffGet

func (this *StaffOutDetail) Handle(c *gin.Context, ctx context.Context) htp.Response {

	rsp, err := model.StaffServer.GetQuitDetail(ctx, &gpb.BaseQuitReq{
		Hid: this.UserId,
	})
	fmt.Println(err)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

/*
 * 描述: 离职分析
 * 路由: staff/getPoolCount
 * 方法: GET
 *********************************************************************/
type GetPoolCount struct {
	CId  int64 `form:"cId" json:"cId"`   //公司ID
	Type int64 `form:"type" json:"type"` //1.代表题干 2.代表选项
	Id   int64 `form:"pid" json:"pid"`   //题干或选项id
}

func (this *GetPoolCount) Handle(c *gin.Context, ctx context.Context) htp.Response {
	rsp, err := model.StaffServer.GetPoolCount(ctx, &gpb.BaseCountReq{
		CId:  this.CId,
		Type: this.Type,
		Id:   this.Id,
	})
	fmt.Println(err)
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}

type PostEdit struct {
	Id      int64  `form:"postId" json:"postId" binding:"required"`     //    岗位ID
	Name    string `form:"postName" json:"postName" binding:"required"` //    岗位名称
	FrameId int64  `form:"frameId" json:"frameId"`                      //    组织架构id
	CId     int64  `form:"cId" json:"cId"`                              //    公司ID
}

func (this *PostEdit) Handle(c *gin.Context, ctx context.Context) htp.Response {
	jwtUser := mod.CurrUser(c)

	if jwtUser.CId < 0 {
		return htp.RespErr(int(StaffCode_ParameterError), "参数错误", nil)
	}

	rsp, err := model.Posts.EditPost(ctx, &gpb.PostBaseReq{
		Id:      this.Id,
		CId:     this.CId,
		Name:    this.Name,
		FrameId: this.FrameId,
	})
	if err != nil {
		return htp.RespModelErr("", err)
	}
	return htp.RespOK("", rsp)
}
